// @ts-ignore
import { defineConfig } from 'vite'
// @ts-ignore
import vue from '@vitejs/plugin-vue';
import { resolve } from 'path';
// @ts-ignore
import AutoImport from 'unplugin-auto-import/vite';
// @ts-ignore
import Components from 'unplugin-vue-components/vite';
// @ts-ignore
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
// @ts-ignore
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';


const getUrl = (url: string) => resolve(__dirname, url);

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  if (mode === "development") {
    return {
      plugins: [
        vue(),
        AutoImport({
          resolvers: [ElementPlusResolver()],
        }),
        Components({
          resolvers: [ElementPlusResolver()],
        }),
        createSvgIconsPlugin({
          // 指定 SVG图标 保存的文件夹路径
          iconDirs: [resolve(process.cwd(), 'src/assets/icons')],
          // 指定 使用svg图标的格式
          symbolId: 'icon-[dir]-[name]',

          /**
           * custom insert position
           * @default: body-last
           */
          // inject?: 'body-last' | 'body-first'

          /**
           * custom dom id
           * @default: __svg__icons__dom__
           */
          //  customDomId: '__svg__icons__dom__',
        }),

      ],
      resolve: {
        alias: {
          "@": getUrl("./src"),
        }
      },
      css: {
        preprocessorOptions: {
          scss: {
            additionalData: `@import "./src/assets/styles/global.scss";`
          }
        }
      }
    }
  }
  return {
    plugins: [
      vue()
    ],
  }
})
